﻿using UnityEngine;
using System.Collections;

public class Aiming2 : MonoBehaviour {
	
	public GUITexture reticle;
	public GameObject target;
	
	LayerMask layerMask;
	
	// Use this for initialization
	void Start () {
		layerMask = (1 << LayerMask.NameToLayer("Player"));
		layerMask = ~layerMask;
	}
	
	// Update is called once per frame
	void Update () {
		
		RaycastHit hit;
		Ray ray = camera.ScreenPointToRay(new Vector3(reticle.transform.position.x * Screen.width, reticle.transform.position.y * Screen.height, 0));
		if(Physics.Raycast(ray, out hit, 10000, layerMask)){
			target.transform.position = hit.point;
		}
		else{
			target.transform.position = transform.position + ray.direction * 1000;
		}
	}
}
